#include <malloc.h>
#include <QDebug>

#include "include/simul.h"
#include "include/core.h"
#include "include/task.h"
#include "include/cluster.h"
const int Primary = 0;
const int Backup = 1;

const int PrioMax = 1;
const int PrioMin = 100;
const int CoreMax = 50;

Core *local_core; //该核的私有调度域
Core cores[CoreMax];
Cluster clusters[10];
Cluster *current_cluster;
Task *current; //表示本核上当前执行的任务实例
Task taskSets[256];
int cluster_num = 0; //集群数
int mode = 3;//默认为异构模式
int cluster_core_num = 0; //集群中调度核数量
int taskNum = 0;
int M = 0; //处理器个数
int Time = 0;
int joined_row = 0;
int simulation_speed = 50;
int Highest_prior=10000;
int taskID;
int chi; //希腊字母X，写作chi，读作kai

task_queue_node *wait_for_join; //待加入任务的队列
vector<Task*> joined_task;

core_list *core_utilization; //按利用率排序的处理器队列

/* ------------------------------------------------------------------------- */

task_queue_node *init_task_list_head(){
    task_queue_node *list;
    list = new task_queue_node;
    list->task = nullptr;
    list->pre = list;
    list->next = list;

    return list;
}

void add_task_list(task_queue_node *New, task_queue_node *pre, task_queue_node *next){
    New->pre = pre;
    New->next = next;
    pre->next = New;
    New->next->pre = New;
}

void add_task_list_tail(task_queue_node *New, task_queue_node *head){
    add_task_list(New, head->pre, head);
}

void del_task_list(task_queue_node *pre, task_queue_node *next){
    pre->next = next;
    next->pre = pre;
}

core_list *init_core_list_head(){
    core_list *head = new core_list;
    head->core = nullptr;
    head->pre = head;
    head->next = head;

    return head;
}

void add_core_list(core_list *New, core_list *pre, core_list *next){
    New->pre = pre;
    New->next = next;
    pre->next = New;
    New->next->pre = New;
}

void add_core_list_tail(core_list *New, core_list *head){
    add_core_list(New, head->pre, head);
}

void del_core_list(core_list *pre, core_list *next){
    pre->next = next;
    next->pre = pre;
}
